<?php
/**
 * Created by IntelliJ IDEA.
 * User: wangfangda
 * Date: 2017/3/6
 * Time: 下午5:21
 */

namespace webjson\cron;


class Event
{

    private $_cmd;
    private $_schedule;

    public function __construct( $cmd )
    {
        $this->_cmd = $cmd;
    }

    /**
     * @return string
     */
    public function getCommand()
    {
        return $this->_cmd;
    }

    /**
     * 每10分钟执行一次
     */
    public function everyTenMinutes()
    {
        $this->_schedule = '*/10 * * * *';
    }

    /**
     * 每天执行一次
     */
    public function everyDaily()
    {
        $this->schedule( '0 0 * * *' );
    }

    /**
     * 每小时执行一次
     */
    public function everyHour()
    {
        $this->schedule( '0 * * * *' );
    }

    /**
     * 每分钟执行一次
     */
    public function everyMinute()
    {
        $this->_schedule = '* * * * *';
    }

    /**
     * 每5分钟执行一次
     */
    public function everyFiveMinutes()
    {
        $this->_schedule = '*/5 * * * *';
    }

    public function everyMonthly()
    {
        $this->_schedule = '0 0 1 * *';
    }

    public function everyWeekly()
    {
        $this->_schedule = '0 0 * * 0';
    }

    /**
     * 自定义crontab
     *
     * @param string $schedule
     */
    public function schedule( $schedule )
    {
        $this->_schedule = $schedule;
    }

    public function getSchedule()
    {
        return $this->_schedule;
    }

    private function _exec( $cmd )
    {

    }

}